<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>案例 | 机器学习（常用科学计算库的使用）基础定位、目标</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../ReadingExtension/index.html" />
    
    
    <link rel="prev" href="../Pandas/section11.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.12"
        data-chapter-title="案例"
        data-filepath="Pandas/section12.md"
        data-basepath=".."
        data-revision="Sat Jul 20 2019 23:53:14 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        机器学习（常用科学计算库的使用）基础定位、目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="ml_pre/index.html">
            
                
                    <a href="../ml_pre/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        机器学习概述
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="ml_pre/section1.html">
            
                
                    <a href="../ml_pre/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        人工智能概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="ml_pre/section2.html">
            
                
                    <a href="../ml_pre/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        人工智能发展历程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ml_pre/section3.html">
            
                
                    <a href="../ml_pre/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        人工智能主要分支
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ml_pre/section4.html">
            
                
                    <a href="../ml_pre/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        机器学习工作流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ml_pre/section5.html">
            
                
                    <a href="../ml_pre/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        机器学习算法分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="ml_pre/section6.html">
            
                
                    <a href="../ml_pre/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        模型评估
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="ml_pre/section7.html">
            
                
                    <a href="../ml_pre/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        Azure机器学习模型搭建实验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ml_pre/section8.html">
            
                
                    <a href="../ml_pre/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        深度学习简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="env/index.html">
            
                
                    <a href="../env/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        机器学习基础环境安装与使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="env/section1.html">
            
                
                    <a href="../env/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="env/section2.html">
            
                
                    <a href="../env/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        jupyter notebook使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="Matplotlib/index.html">
            
                
                    <a href="../Matplotlib/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Matplotlib
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="Matplotlib/section1.html">
            
                
                    <a href="../Matplotlib/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Matplotlib之HelloWorld
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="Matplotlib/section2.html">
            
                
                    <a href="../Matplotlib/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        基础绘图功能 — 以折线图为例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="Matplotlib/section3.html">
            
                
                    <a href="../Matplotlib/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        常见图形绘制
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Numpy/index.html">
            
                
                    <a href="../Numpy/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Numpy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Numpy/section1.html">
            
                
                    <a href="../Numpy/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Numpy的优势
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Numpy/section2.html">
            
                
                    <a href="../Numpy/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        N维数组-ndarray
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Numpy/section3.html">
            
                
                    <a href="../Numpy/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Numpy/section4.html">
            
                
                    <a href="../Numpy/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        ndarray运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Numpy/section5.html">
            
                
                    <a href="../Numpy/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        数组间的运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Numpy/section6.html">
            
                
                    <a href="../Numpy/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        数学：矩阵
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Pandas/index.html">
            
                
                    <a href="../Pandas/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Pandas/section1.html">
            
                
                    <a href="../Pandas/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Pandas/section2.html">
            
                
                    <a href="../Pandas/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Pandas数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="Pandas/section3.html">
            
                
                    <a href="../Pandas/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        基本数据操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Pandas/section4.html">
            
                
                    <a href="../Pandas/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        DataFrame运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Pandas/section5.html">
            
                
                    <a href="../Pandas/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Pandas画图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Pandas/section6.html">
            
                
                    <a href="../Pandas/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件读取与存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Pandas/section7.html">
            
                
                    <a href="../Pandas/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        高级处理-缺失值处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="Pandas/section8.html">
            
                
                    <a href="../Pandas/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        高级处理-数据离散化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="Pandas/section9.html">
            
                
                    <a href="../Pandas/section9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        高级处理-合并
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="Pandas/section10.html">
            
                
                    <a href="../Pandas/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        高级处理-交叉表与透视表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="Pandas/section11.html">
            
                
                    <a href="../Pandas/section11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        高级处理-分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.12" data-path="Pandas/section12.html">
            
                
                    <a href="../Pandas/section12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="ReadingExtension/index.html">
            
                
                    <a href="../ReadingExtension/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        拓展知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="ReadingExtension/1.完整机器学习项目的流程.html">
            
                
                    <a href="../ReadingExtension/1.完整机器学习项目的流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        完整机器学习项目的流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="ReadingExtension/2.独立同分布.html">
            
                
                    <a href="../ReadingExtension/2.独立同分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        独立同分布
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >机器学习（常用科学计算库的使用）基础定位、目标</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="512-&#x6848;&#x4F8B;">5.12 &#x6848;&#x4F8B;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x76EE;&#x6807; <ul>
<li>&#x65E0;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="1-&#x9700;&#x6C42;">1 &#x9700;&#x6C42;</h2>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6709;&#x4E00;&#x7EC4;&#x4ECE;2006&#x5E74;&#x5230;2016&#x5E74;1000&#x90E8;&#x6700;&#x6D41;&#x884C;&#x7684;&#x7535;&#x5F71;&#x6570;&#x636E;</p>
<p>&#x6570;&#x636E;&#x6765;&#x6E90;&#xFF1A;<a href="https://www.kaggle.com/damianpanek/sunday-eda/data" target="_blank">https://www.kaggle.com/damianpanek/sunday-eda/data</a></p>
<ul>
<li>&#x95EE;&#x9898;1&#xFF1A;&#x6211;&#x4EEC;&#x60F3;&#x77E5;&#x9053;&#x8FD9;&#x4E9B;&#x7535;&#x5F71;&#x6570;&#x636E;&#x4E2D;&#x8BC4;&#x5206;&#x7684;&#x5E73;&#x5747;&#x5206;&#xFF0C;&#x5BFC;&#x6F14;&#x7684;&#x4EBA;&#x6570;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x600E;&#x4E48;&#x83B7;&#x53D6;&#xFF1F;</li>
<li>&#x95EE;&#x9898;2&#xFF1A;&#x5BF9;&#x4E8E;&#x8FD9;&#x4E00;&#x7EC4;&#x7535;&#x5F71;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x60F3;rating&#xFF0C;runtime&#x7684;&#x5206;&#x5E03;&#x60C5;&#x51B5;&#xFF0C;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x5448;&#x73B0;&#x6570;&#x636E;&#xFF1F;</li>
<li>&#x95EE;&#x9898;3&#xFF1A;&#x5BF9;&#x4E8E;&#x8FD9;&#x4E00;&#x7EC4;&#x7535;&#x5F71;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x7EDF;&#x8BA1;&#x7535;&#x5F71;&#x5206;&#x7C7B;(genre)&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x5904;&#x7406;&#x6570;&#x636E;&#xFF1F;</li>
</ul>
<h2 id="2-&#x5B9E;&#x73B0;">2 &#x5B9E;&#x73B0;</h2>
<p>&#x9996;&#x5148;&#x83B7;&#x53D6;&#x5BFC;&#x5165;&#x5305;&#xFF0C;&#x83B7;&#x53D6;&#x6570;&#x636E;</p>
<pre><code>%matplotlib inline
import pandas  as pd 
import numpy as np
from matplotlib import pyplot as plt
</code></pre><pre><code class="lang-python"><span class="hljs-comment">#&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;</span>
path = <span class="hljs-string">&quot;./data/IMDB-Movie-Data.csv&quot;</span>
<span class="hljs-comment">#&#x8BFB;&#x53D6;&#x6587;&#x4EF6;</span>
df = pd.read_csv(path)
</code></pre>
<h3 id="21-&#x95EE;&#x9898;&#x4E00;&#xFF1A;">2.1 &#x95EE;&#x9898;&#x4E00;&#xFF1A;</h3>
<p><strong>&#x6211;&#x4EEC;&#x60F3;&#x77E5;&#x9053;&#x8FD9;&#x4E9B;&#x7535;&#x5F71;&#x6570;&#x636E;&#x4E2D;&#x8BC4;&#x5206;&#x7684;&#x5E73;&#x5747;&#x5206;&#xFF0C;&#x5BFC;&#x6F14;&#x7684;&#x4EBA;&#x6570;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x600E;&#x4E48;&#x83B7;&#x53D6;&#xFF1F;</strong> </p>
<ul>
<li>&#x5F97;&#x51FA;&#x8BC4;&#x5206;&#x7684;&#x5E73;&#x5747;&#x5206;</li>
</ul>
<p>&#x4F7F;&#x7528;mean&#x51FD;&#x6570;</p>
<pre><code class="lang-python">df[<span class="hljs-string">&quot;Rating&quot;</span>].mean()
</code></pre>
<ul>
<li>&#x5F97;&#x51FA;&#x5BFC;&#x6F14;&#x4EBA;&#x6570;&#x4FE1;&#x606F;</li>
</ul>
<p>&#x6C42;&#x51FA;&#x552F;&#x4E00;&#x503C;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x5F62;&#x72B6;&#x83B7;&#x53D6;</p>
<pre><code class="lang-python"><span class="hljs-comment">## &#x5BFC;&#x6F14;&#x7684;&#x4EBA;&#x6570;</span>
<span class="hljs-comment"># df[&quot;Director&quot;].unique().shape[0]</span>
np.unique(df[<span class="hljs-string">&quot;Director&quot;</span>]).shape[<span class="hljs-number">0</span>]

<span class="hljs-number">644</span>
</code></pre>
<h3 id="22-&#x95EE;&#x9898;&#x4E8C;&#xFF1A;">2.2 &#x95EE;&#x9898;&#x4E8C;&#xFF1A;</h3>
<p><strong>&#x5BF9;&#x4E8E;&#x8FD9;&#x4E00;&#x7EC4;&#x7535;&#x5F71;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x60F3;Rating&#xFF0C;Runtime (Minutes)&#x7684;&#x5206;&#x5E03;&#x60C5;&#x51B5;&#xFF0C;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x5448;&#x73B0;&#x6570;&#x636E;&#xFF1F;</strong></p>
<ul>
<li>&#x76F4;&#x63A5;&#x5448;&#x73B0;&#xFF0C;&#x4EE5;&#x76F4;&#x65B9;&#x56FE;&#x7684;&#x5F62;&#x5F0F;</li>
</ul>
<p>&#x9009;&#x62E9;&#x5206;&#x6570;&#x5217;&#x6570;&#x636E;&#xFF0C;&#x8FDB;&#x884C;plot</p>
<pre><code class="lang-python">df[<span class="hljs-string">&quot;Rating&quot;</span>].plot(kind=<span class="hljs-string">&apos;hist&apos;</span>,figsize=(<span class="hljs-number">20</span>,<span class="hljs-number">8</span>))
</code></pre>
<p><img src="images/&#x7535;&#x5F71;&#x5206;&#x6570;&#x76F4;&#x65B9;&#x56FE;.png" alt=""></p>
<ul>
<li>Rating&#x8FDB;&#x884C;&#x5206;&#x5E03;&#x5C55;&#x793A;</li>
</ul>
<p>&#x8FDB;&#x884C;&#x7ED8;&#x5236;&#x76F4;&#x65B9;&#x56FE;</p>
<pre><code class="lang-python">plt.figure(figsize=(<span class="hljs-number">20</span>,<span class="hljs-number">8</span>),dpi=<span class="hljs-number">80</span>)
plt.hist(df[<span class="hljs-string">&quot;Rating&quot;</span>].values,bins=<span class="hljs-number">20</span>)
plt.show()
</code></pre>
<p>&#x4FEE;&#x6539;&#x523B;&#x5EA6;&#x7684;&#x95F4;&#x9694;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x6C42;&#x51FA;&#x6700;&#x5927;&#x6700;&#x5C0F;&#x503C;</span>
max_ = df[<span class="hljs-string">&quot;Rating&quot;</span>].max()
min_ = df[<span class="hljs-string">&quot;Rating&quot;</span>].min()

<span class="hljs-comment"># &#x751F;&#x6210;&#x523B;&#x5EA6;&#x5217;&#x8868;</span>
t1 = np.linspace(min_,max_,num=<span class="hljs-number">21</span>)

<span class="hljs-comment"># [ 1.9    2.255  2.61   2.965  3.32   3.675  4.03   4.385  4.74   5.095  5.45   5.805  6.16   6.515  6.87   7.225  7.58   7.935  8.29   8.645  9.   ]</span>

<span class="hljs-comment"># &#x4FEE;&#x6539;&#x523B;&#x5EA6;</span>
plt.xticks(t1)

<span class="hljs-comment"># &#x6DFB;&#x52A0;&#x7F51;&#x683C;</span>
plt.grid()
</code></pre>
<p><img src="images/&#x7535;&#x5F71;&#x5206;&#x6570;&#x76F4;&#x65B9;&#x56FE;1.png" alt=""></p>
<ul>
<li>Runtime (Minutes)&#x8FDB;&#x884C;&#x5206;&#x5E03;&#x5C55;&#x793A;</li>
</ul>
<p>&#x8FDB;&#x884C;&#x7ED8;&#x5236;&#x76F4;&#x65B9;&#x56FE;</p>
<pre><code class="lang-python">plt.figure(figsize=(<span class="hljs-number">20</span>,<span class="hljs-number">8</span>),dpi=<span class="hljs-number">80</span>)
plt.hist(df[<span class="hljs-string">&quot;Runtime (Minutes)&quot;</span>].values,bins=<span class="hljs-number">20</span>)
plt.show()
</code></pre>
<p>&#x4FEE;&#x6539;&#x95F4;&#x9694;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x6C42;&#x51FA;&#x6700;&#x5927;&#x6700;&#x5C0F;&#x503C;</span>
max_ = df[<span class="hljs-string">&quot;Runtime (Minutes)&quot;</span>].max()
min_ = df[<span class="hljs-string">&quot;Runtime (Minutes)&quot;</span>].min()

<span class="hljs-comment"># # &#x751F;&#x6210;&#x523B;&#x5EA6;&#x5217;&#x8868;</span>
t1 = np.linspace(min_,max_,num=<span class="hljs-number">21</span>)

<span class="hljs-comment"># &#x4FEE;&#x6539;&#x523B;&#x5EA6;</span>
plt.xticks(np.linspace(min_,max_,num=<span class="hljs-number">21</span>))

<span class="hljs-comment"># &#x6DFB;&#x52A0;&#x7F51;&#x683C;</span>
plt.grid()
</code></pre>
<p><img src="images/&#x7535;&#x5F71;&#x5206;&#x6570;&#x76F4;&#x65B9;&#x56FE;2.png" alt=""></p>
<h3 id="23-&#x95EE;&#x9898;&#x4E09;&#xFF1A;">2.3 &#x95EE;&#x9898;&#x4E09;&#xFF1A;</h3>
<p><strong>&#x5BF9;&#x4E8E;&#x8FD9;&#x4E00;&#x7EC4;&#x7535;&#x5F71;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x7EDF;&#x8BA1;&#x7535;&#x5F71;&#x5206;&#x7C7B;(genre)&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x5904;&#x7406;&#x6570;&#x636E;&#xFF1F;</strong></p>
<ul>
<li>&#x601D;&#x8DEF;&#x5206;&#x6790;<ul>
<li>&#x601D;&#x8DEF;<ul>
<li>1&#x3001;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5168;&#x4E3A;0&#x7684;dataframe&#xFF0C;&#x5217;&#x7D22;&#x5F15;&#x7F6E;&#x4E3A;&#x7535;&#x5F71;&#x7684;&#x5206;&#x7C7B;&#xFF0C;temp_df</li>
<li>2&#x3001;&#x904D;&#x5386;&#x6BCF;&#x4E00;&#x90E8;&#x7535;&#x5F71;&#xFF0C;temp_df&#x4E2D;&#x628A;&#x5206;&#x7C7B;&#x51FA;&#x73B0;&#x7684;&#x5217;&#x7684;&#x503C;&#x7F6E;&#x4E3A;1</li>
<li>3&#x3001;&#x6C42;&#x548C;</li>
</ul>
</li>
</ul>
</li>
<li>1&#x3001;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5168;&#x4E3A;0&#x7684;dataframe&#xFF0C;&#x5217;&#x7D22;&#x5F15;&#x7F6E;&#x4E3A;&#x7535;&#x5F71;&#x7684;&#x5206;&#x7C7B;&#xFF0C;temp_df</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x8FDB;&#x884C;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x5272;</span>
temp_list = [i.split(<span class="hljs-string">&quot;,&quot;</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> df[<span class="hljs-string">&quot;Genre&quot;</span>]]
<span class="hljs-comment"># &#x83B7;&#x53D6;&#x7535;&#x5F71;&#x7684;&#x5206;&#x7C7B;</span>
genre_list = np.unique([i <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> temp_list <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> j]) 

<span class="hljs-comment"># &#x589E;&#x52A0;&#x65B0;&#x7684;&#x5217;</span>
temp_df = pd.DataFrame(np.zeros([df.shape[<span class="hljs-number">0</span>],genre_list.shape[<span class="hljs-number">0</span>]]),columns=genre_list)
</code></pre>
<ul>
<li>2&#x3001;&#x904D;&#x5386;&#x6BCF;&#x4E00;&#x90E8;&#x7535;&#x5F71;&#xFF0C;temp_df&#x4E2D;&#x628A;&#x5206;&#x7C7B;&#x51FA;&#x73B0;&#x7684;&#x5217;&#x7684;&#x503C;&#x7F6E;&#x4E3A;1</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1000</span>):
    <span class="hljs-comment">#temp_list[i] [&apos;Action&apos;,&apos;Adventure&apos;,&apos;Animation&apos;]</span>
    temp_df.ix[i,temp_list[i]]=<span class="hljs-number">1</span>
print(temp_df.sum().sort_values())
</code></pre>
<ul>
<li>3&#x3001;&#x6C42;&#x548C;,&#x7ED8;&#x56FE;</li>
</ul>
<pre><code class="lang-python">temp_df.sum().sort_values(ascending=<span class="hljs-keyword">False</span>).plot(kind=<span class="hljs-string">&quot;bar&quot;</span>,figsize=(<span class="hljs-number">20</span>,<span class="hljs-number">8</span>),fontsize=<span class="hljs-number">20</span>,colormap=<span class="hljs-string">&quot;cool&quot;</span>)


Musical        <span class="hljs-number">5.0</span>
Western        <span class="hljs-number">7.0</span>
War           <span class="hljs-number">13.0</span>
Music         <span class="hljs-number">16.0</span>
Sport         <span class="hljs-number">18.0</span>
History       <span class="hljs-number">29.0</span>
Animation     <span class="hljs-number">49.0</span>
Family        <span class="hljs-number">51.0</span>
Biography     <span class="hljs-number">81.0</span>
Fantasy      <span class="hljs-number">101.0</span>
Mystery      <span class="hljs-number">106.0</span>
Horror       <span class="hljs-number">119.0</span>
Sci-Fi       <span class="hljs-number">120.0</span>
Romance      <span class="hljs-number">141.0</span>
Crime        <span class="hljs-number">150.0</span>
Thriller     <span class="hljs-number">195.0</span>
Adventure    <span class="hljs-number">259.0</span>
Comedy       <span class="hljs-number">279.0</span>
Action       <span class="hljs-number">303.0</span>
Drama        <span class="hljs-number">513.0</span>
dtype: float64
</code></pre>
<p><img src="images/genre&#x5206;&#x7C7B;&#x7ED3;&#x679C;.png" alt=""></p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Pandas/section11.html" class="navigation navigation-prev " aria-label="Previous page: 高级处理-分组与聚合"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../ReadingExtension/index.html" class="navigation navigation-next " aria-label="Next page: 拓展知识"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"katex":{},"expandable-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
